#pragma once

#include <sys/epoll.h>
// #include <vector>

#include "./Poller.h"
// #include "../utility/Timestamp.h"

class Channel;

/**
 * epoll的使用:
 * 1. epoll_create
 * 2. epoll_ctl (add, mod, del)
 * 3. epoll_wait
 **/
class EPollPoller : public Poller
{
public:
    EPollPoller(EventLoop *loop);
    ~EPollPoller() override;

    void updateChannel(Channel *chan) override;
    void removeChannel(Channel *chan) override;
    Timestamp poll(const int timeoutMs, ChannelVector *activeChans) override;

private:
    // epoll_ctl
    void updateChannel(int op, Channel *chan);
    // 填写活跃的连接
    void fillActiveChannels(int eventNum, ChannelVector *activeChans) const;

    int epollFd_;
    using EventVector = std::vector<epoll_event>;
    EventVector revents_; // epoll_wait返回的待办事件
    static const int kInitReventVectorSize = 16;
};